package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品模块")
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 添加菜品 有图片 有口味 到数据库
     * @param dishDTO
     * @return
     */
    @PostMapping
    @ApiOperation("菜品添加")
    public Result insertByDish(@RequestBody DishDTO dishDTO){
        log.info("完成添加菜品",dishDTO);

        dishService.insertByDish(dishDTO);

        return Result.success();
    }


    /**
     * 分页查询接口
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result selectByPage(DishPageQueryDTO dishPageQueryDTO){
        log.info("进行菜品分页查询");
        PageResult pageResult=dishService.selectByPage(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 批量删除菜品
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Integer> ids){
        dishService.deleteByids(ids);
        return Result.success();
    }

    /**
     * 修改状态
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result putstatus(@PathVariable Integer status,@RequestParam("id") Integer id){
        dishService.putstatus(status,id);
        return Result.success();
    }

    /**
     * 回显 数据 根据id
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        DishVO dishVO=dishService.selectById(id);
        return Result.success(dishVO);
    }

    @PutMapping
    public Result putByList(@RequestBody DishDTO dishDTO){
        dishService.putByList(dishDTO);
        return Result.success();
    }

    @GetMapping("/list")
    public Result selectByIdDish(Long categoryId){
        List<Dish> list=dishService.selectByCategoryId(categoryId);
        return Result.success(list);
    }
}





















